/**********************************************************************************************/
/**********************************************************************************************/
/***************Main Coding for****************************************************************/
**		"Climate Adaptation Risk and Capital Structure: 
**		Evidence From State Climate Adaptation Plans"				  

*About the uploaded data:
*(1) All data sources are clearly demonstrated in the paper.
*(2) The sample data illustrates the format of the actual datasets.
*(3) The GroupID is a randomized number corresponding to the firm identifier.
*    The actual firm identifier (gvkey) is masked in the sample data.		
/**********************************************************************************************/
/**********************************************************************************************/


clear * 

global datadir "~"

cd "$datadir"

global control "ln_assets lnage mtob roa tangibility dvdummy modified_altmanz rd1 gsp_growth  blue"
global key_indep "inter treated plan_post"

global depvar_base "net_market_leverage net_book_leverage "

global clustervar1 "vce(cluster stcode)"



	
	
	
	
/**********************************************************************/
/***********************Table 1  -- Summary Stat***********************/
/**********************************************************************/
clear *
set more off
use FM_MainSample.dta

global sumvar " net_market_leverage net_book_leverage $control "

est clear
quietly eststo: estpost sum  $sumvar at age, detail	
esttab using Table1_Summary.csv, cells ("count(fmt(a3)) mean p50 sd p25  p75") t(3) replace
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/











/**********************************************************************/
/***********************Table 2  -- Baseline***************************/
/**********************************************************************/
**1. Baseline;
clear *
set more off
use FM_MainSample.dta

	estimates clear 
	set more off
	foreach y in $depvar_base  {		
		eststo: quietly reghdfe `y' $key_indep $control , $clustervar1  absorb(sic4 fyear stcode )
	}

global repoption "b(3) t(3) ar2(4) nogaps  keep($key_indep $control) star(* 0.10 ** 0.05 *** 0.01)"
esttab using Table2_BaselineOLS.csv, $repoption  replace


**2. Dynamic Model;
gen p5=0
	replace p5=1 if year_diff<-4
gen p4=0
	replace p4=1 if year_diff==-4
gen p3=0
	replace p3=1 if year_diff==-3
gen p2=0
	replace p2=1 if year_diff==-2
gen p1=0
	replace p1=1 if year_diff==-1
gen g0=0
	replace g0=1 if year_diff==0
gen g1=0
	replace g1=1 if year_diff==1
gen g2=0
	replace g2=1 if year_diff==2
gen g3=0
	replace g3=1 if year_diff==3
gen g4=0
	replace g4=1 if year_diff==4
gen g5=0
	replace g5=1 if year_diff>4
	
global dynamic "p5 p4 p3 p2 p1 g0 g1 g2 g3 g4 g5"

	foreach x in $dynamic {
		gen `x'_treated = `x' * treated
	}

	global dynamic_inter " p4_treated p3_treated p2_treated p1_treated g0_treated g1_treated g2_treated g3_treated g4_treated g5_treated"

	estimates clear 
	set more off
	foreach y in $depvar_base  {		

		eststo: quietly reghdfe `y' $dynamic_inter plan_post treated $control, $clustervar1  absorb(sic4 fyear stcode )
		
	}
global repoption "b(3) t(3) ar2(4) nogaps  keep($dynamic_inter ) star(* 0.10 ** 0.05 *** 0.01)"
esttab using Table2_DynamicModel.csv, $repoption  replace
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/









/**********************************************************************/
/**************Table 3 -- Specificity of SCAP**************************/
/**********************************************************************/
clear *
set more off
use FM_SCAPdetails.dta

global ln_scap_var "ln_goals ln_planning ln_law ln_monitoring"

	estimates clear 
	set more off
	foreach y in $depvar_base  {	

	foreach ln_scap_var in $ln_scap_var {

	gen inter3= plan_post * treated * `ln_scap_var'
	gen inter = plan_post * treated
	gen inter1 = plan_post * `ln_scap_var'
	gen inter2 = treated * `ln_scap_var'

		eststo: quietly reghdfe `y' inter3 inter1 inter2 inter plan_post treated `ln_scap_var' $control , $clustervar1  absorb(sic4 fyear stcode )
		
	drop inter3 inter inter1 inter2
	}
	}
global repoption "b(3) t(3) ar2(4) nogaps  keep(inter3 inter2 inter plan_post treated) star(* 0.10 ** 0.05 *** 0.01)"
esttab using Table3_SCAPdetails.csv, $repoption replace
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/






/**********************************************************************/
/********************Table 4 -- Physical climate risk******************/
/**********************************************************************/
clear *
set more off
use FM_MainSample.dta

	eststo: quietly reghdfe net_market_leverage $key_indep $control  if (aqi_median_q2==1  ) , $clustervar1   absorb(sic4  fyear stcode)
	eststo: quietly reghdfe net_book_leverage $key_indep $control  if (aqi_median_q2==1  ) , $clustervar1   absorb(sic4  fyear stcode)
		
	eststo: quietly reghdfe net_market_leverage $key_indep $control  if (aqi_median_q2==0  ) , $clustervar1   absorb(sic4  fyear stcode)	
	eststo: quietly reghdfe net_book_leverage $key_indep $control  if (aqi_median_q2==0  ) , $clustervar1   absorb(sic4  fyear stcode)

esttab using Table4_AirQualityPre.csv, keep($key_indep)  cells(b(star fmt(3)) t(par fmt(3))) ar2(4) starlevels( * 0.10 ** 0.05 *** 0.01) nogap replace 
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/






/**********************************************************************/
/*******************Table 5 -- Regulatory Risk**************************/
/**********************************************************************/
clear *
set more off
use FM_MainSample.dta
		
	eststo: quietly reghdfe net_market_leverage $key_indep $control  if ((cpu_group5==2) | (cpu_group5==3)  ) , $clustervar1   absorb(sic4  fyear stcode)	
	eststo: quietly reghdfe net_book_leverage $key_indep $control  if ((cpu_group5==2) | (cpu_group5==3)  ) , $clustervar1   absorb(sic4  fyear stcode)
	
	eststo: quietly reghdfe net_market_leverage $key_indep $control  if ((cpu_group5==0) | (cpu_group5==1) ) , $clustervar1   absorb(sic4  fyear stcode)	
	eststo: quietly reghdfe net_book_leverage $key_indep $control  if ((cpu_group5==0) | (cpu_group5==1) ) , $clustervar1   absorb(sic4  fyear stcode)
	
esttab using Table5_RegulatoryRisk.csv, keep($key_indep)  cells(b(star fmt(3)) t(par fmt(3))) ar2(4) starlevels( * 0.10 ** 0.05 *** 0.01) nogap replace 
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/




/**********************************************************************/
/****************Table 6 Business risk*********************************/
/**********************************************************************/
global depvar_qlybrisk "stdoia stdniq stdepsincl"
global control_lev "ln_assets lnage mtob roa tangibility cash1 book_leverage dvdummy modified_altmanz rd1 gsp_growth  blue"
global control_levwomtb "ln_assets lnage roa tangibility cash1 market_leverage dvdummy modified_altmanz rd1 gsp_growth  blue"


clear *
use FM_Businessrisk.dta

**Col(1)-(3)
estimates clear 
set more off
foreach y in $depvar_qlybrisk {	
	eststo: quietly reghdfe `y' $key_indep $control_lev , $clustervar1  absorb(sic4 stcode )
}

global repoption "b(3) t(3) ar2(4) nogaps  keep($key_indep ) star(* 0.10 ** 0.05 *** 0.01)"
esttab using Table6_BusinessRisk.csv, $repoption replace


**Col(4)
clear *
set more off
use FM_MainSample.dta

estimates clear
set more off

	eststo: quietly reghdfe tobinsq $key_indep $control_levwomtb, $clustervar1  absorb(sic4 fyear stcode )

global repoption "b(3) t(3) ar2(4) nogaps  keep($key_indep $control_levwomtb) star(* 0.10 ** 0.05 *** 0.01)"
esttab using Table6_FirmValue.csv, $repoption replace
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/








/**********************************************************************/
/****************Table 7 -- Financial Mix******************************/
/**********************************************************************/
clear *
set more off
use FM_MainSample.dta

	eststo: quietly  reghdfe d_cash1 treated $control if (cyear>plan_final_year), $clustervar1 absorb(sic4  fyear stcode)
	eststo: quietly  reghdfe net_equity_issue treated $control if (cyear>plan_final_year), $clustervar1 absorb(sic4  fyear stcode)
	eststo: quietly  reghdfe net_debt_issue treated $control if (cyear>plan_final_year), $clustervar1 absorb(sic4  fyear stcode)
		
esttab using Table7_FinancialMix.csv, keep(treated)  cells(b(star fmt(3)) t(par fmt(3))) ar2(4) starlevels( * 0.10 ** 0.05 *** 0.01) nogap replace
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/












/**********************************************************************/
/****************Table 8 -- LT vs ST Leverage**************************/
/**********************************************************************/
global depvar_ls "lt_market_leverage lt_book_leverage st_market_leverage st_book_leverage"

clear *
set more off
use FM_MainSample.dta

	foreach y in $depvar_ls {	
		eststo: quietly reghdfe `y' $key_indep  $control  , $clustervar1 absorb(sic4  fyear stcode)	
	}
esttab using Table8_LTvsSTLeverage.csv,  keep($key_indep) cells(b(star fmt(3)) t(par fmt(3))) ar2(4) starlevels( * 0.10 ** 0.05 *** 0.01) nogap replace
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/


















/**********************************************************************/
/***********************Appendix***************************************/
/**********************************************************************/




/**********************************************************************/
/*****************Appx3.1 -- Matched Sample****************************/
/**********************************************************************/
clear *
use FM_MatchedSample1_Regression.dta

estimates clear 
set more off
	foreach y in $depvar_base  {	

		eststo: quietly reghdfe `y' $key_indep $control, $clustervar1  noabsorb
	}
global repoption "b(3) t(3) ar2(4) nogaps  keep($key_indep) star(* 0.10 ** 0.05 *** 0.01)"
esttab using Appx3.1PanelB_MatchedSample_Regression.csv, $repoption  replace


clear *
use FM_MatchedSample2_Comparison.dta

	global ttest_var "net_market_leverage net_book_leverage ln_assets lnage mtob roa tangibility dvdummy modified_altmanz rd1"
	bysort treated: eststo: quietly estpost sum  $ttest_var if year_diff==-1
	
eststo: quietly estpost ttest $ttest_var if year_diff==-1, by(treated) 
esttab using Appx3.1PanelA_MatchedSample_Comparison.csv, cell("mean count b t p")  replace
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/






/**********************************************************************/
/*****************Appx3.2 -- Placebo Tests****************************/
/**********************************************************************/
clear *
use FM_placebo.dta

	estimates clear 
	set more off
	foreach y in $depvar_base  {		

		eststo: quietly reghdfe `y' treated##PseudoPost treated PseudoPost $control, $clustervar1  absorb(sic4 fyear stcode )
		eststo: quietly reghdfe `y' PseudoTreat##plan_post PseudoTreat plan_post $control, $clustervar1  absorb(sic4 fyear stcode )
		
	}
global repoption "b(3) t(3) ar2(4) nogaps  star(* 0.10 ** 0.05 *** 0.01)"
esttab using Appx3.2_PseudoTests.csv, drop($control) $repoption  replace
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/







/**********************************************************************/
/****************Appx3.3 -- Confounding Effects************************/
/**********************************************************************/
clear *
set more off
use FM_MainSample.dta

	gen crisis = 0
	replace crisis = 1 if  (cyear >= 2007 & cyear <=2008)

	est clear
	foreach y in $depvar_base  {
	eststo: quietly reghdfe `y' $key_indep $control crisis, $clustervar1  absorb(sic4 fyear stcode )		
	}

	foreach y in $depvar_base  {
	eststo: quietly reghdfe `y' $key_indep $control crisis envi_post_5, $clustervar1  absorb(sic4 fyear stcode )
		
	}

global repoption "b(3) t(3) ar2(4) nogaps  keep($key_indep crisis envi_post_5) star(* 0.10 ** 0.05 *** 0.01)"
esttab using Appx3.3_Confounding.csv, $repoption replace
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/*****************Appx3.4 -- Predicting SCAP***************************/
/**********************************************************************/
clear *
use FM_STYR_LEVERAGE2.dta
stcox z_styr_nml  z_styr_mtob z_unemp  z_lnstatepop   z_gsp_growth, $options
stcox z_styr_nbl  z_styr_mtob z_unemp  z_lnstatepop   z_gsp_growth, $options 

/**********************************************************************/
/**********************************************************************/
/**********************************************************************/





/**********************************************************************/
/*****************Appx3.5 -- Eliminating the Years between Initiation and Finalization of State Climate Adaptation Plans***************/
/**********************************************************************/
clear *
set more off
use FM_MainSample.dta

gen cloudyyear=0
replace cloudyyear=1 if (plan_post_initiate==1 & plan_post==0)

estimates clear 
set more off
foreach y in $depvar_base  {		
	
	eststo: quietly reghdfe `y' $key_indep $control if cloudyyear==0, $clustervar1  absorb(sic4 fyear stcode )
	
}
global repoption "b(3) t(3) ar2(4) nogaps  keep($key_indep) star(* 0.10 ** 0.05 *** 0.01)"
esttab using Appx3.5_DeleteBetweenInitiationFinal.csv, $repoption  replace

drop cloudyyear
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/




/**********************************************************************/
/******************Appx3.6 Geo Dispersion****************************/
/**********************************************************************/
clear *
set more off
use FM_MainSample.dta


	eststo: quietly reghdfe net_market_leverage $key_indep  $control if (single_state==1 & cyear <= 2014) , $clustervar1 absorb(sic4  fyear stcode)
	eststo: quietly reghdfe net_book_leverage $key_indep  $control if (single_state==1 & cyear <= 2014) , $clustervar1 absorb(sic4  fyear stcode)

	eststo: quietly reghdfe net_market_leverage $key_indep  $control  if (single_state==0 & cyear <= 2014) , $clustervar1 absorb(sic4  fyear stcode)
	eststo: quietly reghdfe net_book_leverage $key_indep  $control  if (single_state==0 & cyear <= 2014) , $clustervar1 absorb(sic4  fyear stcode)
	
esttab using Appx3.6_GeoDispersion.csv, keep($key_indep)  cells(b(star fmt(3)) t(par fmt(3))) ar2(4) starlevels( * 0.10 ** 0.05 *** 0.01) nogap replace
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/







/**********************************************************************/
/******************Appx3.7 Alternative Cluster*************************/
/**********************************************************************/
clear *
set more off
use FM_MainSample.dta


	estimates clear 
	set more off
	foreach y in $depvar_base  {	
		
		eststo: quietly reghdfe `y' $key_indep $control , vce(cluster gvkey)  absorb(sic4 fyear stcode )
		eststo: quietly reghdfe `y' $key_indep $control , vce(cluster stcode fyear) absorb(sic4 fyear stcode )
	}	
esttab using Appx3.7_AlterCluster.csv, keep($key_indep)  cells(b(star fmt(3)) t(par fmt(3))) ar2(4) starlevels( * 0.10 ** 0.05 *** 0.01) nogap replace
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/

